differences between "d.clear()" and "d={}"
Posted
by Tshepang
on Stack Overflow
See other posts from Stack Overflow
or by Tshepang
Published on 2010-04-28T19:30:42Z
Indexed on
2010/04/28
19:37 UTC
Read the original article
Hit count: 263
On my machine, the execution speed between "d.clear()" and "d={}" is over 100ns so am curious why one would use one over the other.
import timeit
def timing():
d = dict()
if __name__=='__main__':
t = timeit.Timer('timing()', 'from __main__ import timing')
print t.repeat()
© Stack Overflow or respective owner